package com.jamin.aabill.data;

import org.json.JSONObject;

import android.database.Cursor;

import com.jamin.aabill.api.BillApi;
import com.jamin.aabill.api.BillException;
import com.jamin.aabill.api.BillResponse;
import com.jamin.aabill.db.CircleTableMetaData;
import com.jamin.aabill.http.Response;

/**
 * ClassName:Circle
 * 
 * @author   wangjieming
 * @version  1.0
 * @since    v1.0
 * @Date	 2012-7-24 下午3:48:00 
 */
public class Circle extends BillResponse{


	public static final int CIRCLE_NOT_ACTIVE = 0;
	public static final int CIRCLE_ACTIVE = 1;
	
	
	public Circle(long circleId , String name , String description){
		setId(circleId);
		setCircle_name(name);
		setCircle_description(description);
		setActive(1);
		setCircle_create_time(System.currentTimeMillis());
	}

	public Circle(Cursor cur){
		setId(cur.getLong(cur.getColumnIndex(CircleTableMetaData.ID)));
		setCircle_name(cur.getString(cur.getColumnIndex(CircleTableMetaData.NAME)));
		setCircle_description(cur.getString(cur.getColumnIndex(CircleTableMetaData.DESCRIPTION)));
		setCircle_create_time(cur.getLong(cur.getColumnIndex(CircleTableMetaData.CREATE_AT)));
		setActive(cur.getInt(cur.getColumnIndex(CircleTableMetaData.ISACTIVE)));
		
	}


	/**
	 * get circle list api obj<br> 
	 * Creates a new instance of Circle.
	 * 
	 * @param jsonObj
	 */
	public Circle(JSONObject jsonObj){
		setCircle_name(getString("name", jsonObj, true));
		setCircle_description(getString("description", jsonObj, true));
		setCircle_create_time(getLong("created_at", jsonObj));
		setActive(getInt("active", jsonObj));
	}

	/**
	 * 修改，新增圈子调用接口返回对象<br>
	 * Creates a new instance of Circle.
	 *
	 * @param res
	 * @param ctx
	 * @throws BillException
	 */
	public Circle(Response res) throws BillException{
		super(res, BillApi.TYPE_JSONOBJECT);

	}



	long id;							//circleID
	long owner_id;						//circle创建者ID
	String circle_name;                 //名字
	String circle_description;          //描述
	long circle_update_time;			//更新时间
	long circle_create_time;	        //创建时间
	double circle_contribution;         //贡献值     由Bill账单算出
	int active;							//是否关闭  1为开启   0为关闭


	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public long getOwner_id() {
		return owner_id;
	}

	public void setOwner_id(long owner_id) {
		this.owner_id = owner_id;
	}

	public String getCircle_name() {
		return circle_name;
	}

	public void setCircle_name(String circle_name) {
		this.circle_name = circle_name;
	}

	public String getCircle_description() {
		return circle_description;
	}

	public void setCircle_description(String circle_description) {
		this.circle_description = circle_description;
	}

	public long getCircle_create_time() {
		return circle_create_time;
	}

	public void setCircle_create_time(long circle_create_time) {
		this.circle_create_time = circle_create_time;
	}

	public double getCircle_contribution() {
		return circle_contribution;
	}

	public void setCircle_contribution(double circle_contribution) {
		this.circle_contribution = circle_contribution;
	}

	public int getActive() {
		return active;
	}

	public void setActive(int active) {
		this.active = active;
	}


	public long getCircle_update_time() {
		return circle_update_time;
	}


	public void setCircle_update_time(long circle_update_time) {
		this.circle_update_time = circle_update_time;
	}


	@Override
	public String toString() {
		return "Circle{" +
				"circle_name='" + circle_name +
				", circle_description='" + circle_description +'\'' +
				", circle_create_time='" + circle_create_time + '\'' +
				", circle_update_time='" + circle_update_time + '\'' +
				", circle_contribution='" + circle_contribution +"\'" +
				", active='" + active + '\'' +"}";
	}

}





